
Class('devicemanager', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI"], 
        //requried class for this com
        required:["linb.UI.Dialog", "linb.UI.Pane", "linb.UI.Label", "linb.UI.Input", "linb.UI.Button", "linb.UI.TreeGrid", "linb.UI.ComboInput", "linb.UI.CheckBox", "linb.DataBinder"], 

        properties:{}, 
        dmself:null, 
        parents:null, 
        db:null, 
        events:{}, 
        iniResource:function(com, threadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0))};
            
            append((new linb.DataBinder)
                .host(host,"databinder1")
                .setName("dataset_deviceinfo")
            );
            
            append((new linb.UI.Dialog)
                .host(host,"dialog1")
                .setLeft(160)
                .setTop(30)
                .setWidth(860)
                .setHeight(552)
                .setCaption("设备管理")
                .setMinBtn(false)
                .setMaxBtn(false)
                .onRender("_dialog1_onrender")
                .beforeDestroy("_dialog1_beforedestroy")
            );
            
            host.dialog1.append((new linb.UI.Pane)
                .host(host,"pane6")
                .setDock("left")
                .setWidth(250)
            );
            
            host.pane6.append((new linb.UI.Label)
                .host(host,"label1")
                .setLeft(0)
                .setTop(20)
                .setWidth(70)
                .setCaption("设备IP地址")
            );
            
            host.pane6.append((new linb.UI.Input)
                .host(host,"ip_search")
                .setLeft(70)
                .setTop(20)
                .setWidth(150)
            );
            
            host.pane6.append((new linb.UI.Button)
                .host(host,"btnSearch")
                .setLeft(158)
                .setTop(48)
                .setWidth(62)
                .setCaption("查询")
                .onClick("_btnsearch_onclick")
            );
            
            host.pane6.append((new linb.UI.TreeGrid)
                .host(host,"devicegrid")
                .setDock("bottom")
                .setHeight(426)
                .setHeader([{"id":"id", "width":20, "type":"label", "caption":"ID"}, {"id":"ip", "width":100, "type":"label", "caption":"设备IP"}, {"id":"dtype", "width":10, "type":"label", "caption":"dtype"}, {"id":"descri", "width":80, "type":"label", "caption":"设备类型"}])
                .onRowSelected("_devicegrid_onrowselected")
            );
            
            host.dialog1.append((new linb.UI.Pane)
                .host(host,"pane7")
                .setDock("fill")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label2")
                .setLeft(20)
                .setTop(20)
                .setWidth(80)
                .setCaption("设备IP地址")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label3")
                .setLeft(20)
                .setTop(60)
                .setWidth(80)
                .setCaption("读共同体")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label4")
                .setLeft(300)
                .setTop(60)
                .setWidth(80)
                .setCaption("写共同体")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label5")
                .setLeft(20)
                .setTop(104)
                .setWidth(80)
                .setCaption("SNMP版本")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label6")
                .setLeft(333)
                .setTop(104)
                .setWidth(50)
                .setCaption("端口号")
            );
            
            host.pane7.append((new linb.UI.Button)
                .host(host,"btnSNMPUpdate")
                .setLeft(440)
                .setTop(140)
                .setWidth(100)
                .setHeight(30)
                .setCaption("更新数据")
                .onClick("_btnsnmpupdate_onclick")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label7")
                .setLeft(20)
                .setTop(190)
                .setWidth(80)
                .setCaption("设备名称")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label8")
                .setLeft(20)
                .setTop(229)
                .setWidth(80)
                .setCaption("设备描述")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label9")
                .setLeft(303)
                .setTop(191)
                .setWidth(80)
                .setCaption("设备类型")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label10")
                .setLeft(20)
                .setTop(269)
                .setWidth(80)
                .setCaption("产品描述")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label11")
                .setLeft(37)
                .setTop(309)
                .setWidth(60)
                .setCaption("设备OID")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label12")
                .setLeft(0)
                .setTop(429)
                .setWidth(100)
                .setCaption("系统已启动时间")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label13")
                .setLeft(40)
                .setTop(349)
                .setWidth(60)
                .setCaption("产品ID")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label14")
                .setLeft(20)
                .setTop(389)
                .setWidth(80)
                .setCaption("放置地点")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label15")
                .setLeft(310)
                .setTop(389)
                .setWidth(60)
                .setCaption("服务码")
            );

            
            host.pane7.append((new linb.UI.Button)
                .host(host,"btnModify")
                .setLeft(250)
                .setTop(480)
                .setHeight(20)
                .setCaption("修改设备")
                .onClick("_btnmodify_onclick")
            );
            
            host.pane7.append((new linb.UI.Button)
                .host(host,"btnDelete")
                .setLeft(420)
                .setTop(480)
                .setHeight(20)
                .setCaption("删除设备")
                .onClick("_btndelete_onclick")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"id")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("id")
                .setLeft(410)
                .setTop(30)
                .setVisibility("hidden")
                .setValue("-1")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"ip")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("ip")
                .setLeft(110)
                .setTop(20)
                .setWidth(170)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"rcommunity")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("rcommunity")
                .setLeft(110)
                .setTop(55)
                .setWidth(100)
                .setValue("public")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"wcommunity")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("wcommunity")
                .setLeft(390)
                .setTop(55)
                .setWidth(100)
                .setValue("public")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"port")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("port")
                .setLeft(390)
                .setTop(101)
                .setWidth(60)
                .setValue("161")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"version")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("version")
                .setLeft(110)
                .setTop(100)
                .setWidth(110)
                .setItems([{"id":1, "caption":"SNMP v1", "image":"img/demo.gif"}, {"id":2, "caption":"SNMP v2", "image":"img/demo.gif"}])
                .setValue("1")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"name")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("name")
                .setLeft(110)
                .setTop(190)
                .setWidth(190)
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"dtype")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("dtype")
                .setLeft(400)
                .setTop(190)
                .setItems([{"id":0, "caption":"主机设备", "image":"img/demo.gif"}, {"id":1, "caption":"网络设备", "image":"img/demo.gif"}])
                .setValue("0")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"descri")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("descri")
                .setLeft(110)
                .setTop(229)
                .setWidth(410)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"product_desc")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("product_desc")
                .setLeft(110)
                .setTop(269)
                .setWidth(410)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"device_id")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("device_id")
                .setLeft(110)
                .setTop(308)
                .setWidth(410)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"product_id")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("product_id")
                .setLeft(110)
                .setTop(349)
                .setWidth(410)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"location")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("location")
                .setLeft(110)
                .setTop(389)
                .setWidth(200)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"sysService")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("sysService")
                .setLeft(380)
                .setTop(389)
                .setWidth(140)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"sysUptime")
                .setDataBinder("dataset_deviceinfo")
                .setDataField("sysUptime")
                .setLeft(110)
                .setTop(429)
                .setWidth(200)
            );
            
            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        iniExComs:function(com, hreadid){
        }, 
        setWhoisParent:function(myparents) {
            parents = myparents;
        }, 
        _dialog1_beforedestroy:function (profile) {
            if (parents != null) {
                oo = _.unserialize(parents.menubar1.getTagVar());                
                oo.mmodify_device = 0;
                parents.menubar1.setTagVar(_.serialize(oo));
            }
            linb.DataBinder.destroyAll();
            return true;
        }, 
        _dialog1_onrender:function (profile) {
            dmself = this;
            dmself.devicegrid.showColumn('dtype',false);
            dmself.CallRemote('list','',dmself.process_search);
        }, 
        CallRemote:function(cmd,datas,processfun){
            linb.request("/NetDM4Web/devicemanager.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returnpkg = _.unserialize(rep);
                processfun(returnpkg);
            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });
        }, 
        process_search:function(pkg) {
            if (pkg.code == 0) {
                dmself.devicegrid.setRows(_.unserialize(pkg.datas));
            } else {
                linb.UI.Dialog.alert('提示',pkg.messages);
            }
        }, 
        SNMPObject:function() {
            this.ip = '127.0.0.1';
            this.dtype = 1;
            this.ver = 1;
            this.port = 161;
            this.rcommunity = 'public';
            this.wcommunity = 'public';
        }, 
        process_snmp:function(pkg) {
            if (pkg.code == 0) {
                so = _.unserialize(pkg.datas);
                dmself.databinder1.resetValue(so);
            }
            if (pkg.code < 0){
                linb.UI.Dialog.alert('提示',pkg.messages);
            }
        }, 
        process_displayinfo:function(pkg) {
            if (pkg.code == 0) {
                so = _.unserialize(pkg.datas);
                dmself.databinder1.resetValue(so);
            }
            if (pkg.code < 0){
                linb.UI.Dialog.alert('提示',pkg.messages);
            }
        }, 
        process_saveok:function(pkg) {
            if (pkg.code == 0) {
            	linb.UI.Dialog.alert('提示',pkg.messages);
                dmself.databinder1.updateValue();
            }
            if (pkg.code < 0){
                linb.UI.Dialog.alert('提示',pkg.messages);
            }
        },
        _btnsearch_onclick:function (profile, e, src, value) {
            dmself.CallRemote('search',dmself.ip_search.updateValue().getValue(),dmself.process_search);
        }, 
        _btnsnmpupdate_onclick:function (profile, e, src, value) {
            so = new dmself.SNMPObject();
            so.ip = dmself.ip.updateValue().getValue();
            so.dtype = dmself.dtype.updateValue().getValue();
            so.ver = dmself.version.updateValue().getValue();
            so.port = dmself.port.updateValue().getValue();
            so.rcommunity = dmself.rcommunity.updateValue().getValue();
            so.wcommunity = dmself.wcommunity.updateValue().getValue();
            dmself.CallRemote('fd',_.serialize(so),dmself.process_snmp);
        }, 
        _btnmodify_onclick:function (profile, e, src, value) {
            datas = _.serialize(dmself.databinder1.getValue());
            dmself.CallRemote('save',datas,dmself.process_saveok);
        }, 
        process_del:function(pkg) {
            if (pkg.code == 0) {
                dmself.CallRemote('list','',dmself.process_search);
                linb.UI.Dialog.alert('提示',pkg.messages);
            }
            if (pkg.code < 0){
                linb.UI.Dialog.alert('提示',pkg.messages);
            }            
        },
        _btndelete_onclick:function (profile, e, src, value) {
            v = dmself.id.getValue();
            if (v != null && v != '') {
                datas = _.serialize(dmself.databinder1.getValue());
                dmself.CallRemote('delete',datas,dmself.process_del);            
            }
        }, 
        _devicegrid_onrowselected:function (profile, row, src) {
            dmself.$row = row;
            so = new dmself.SNMPObject();
            so.id = row.cells[0].value;
            so.ip = row.cells[1].value;
            so.dtype = row.cells[2].value;
            dmself.CallRemote('ld',_.serialize(so),dmself.process_displayinfo);
        }
    }
});